<?php
namespace App\Http\Questionnaire\Controllers;

use Illuminate\Http\Request;
use App\Http\Admin\Controllers\Controller as Controller;
use Illuminate\Support\Facades\Redis;
use Illuminate\Support\Facades\DB;
use App\Http\OS\Controllers\NewsOSController;
use App\Http\Alipay\Controllers\AlipayController;
use App\Http\Questionnaire\Controllers\ActionController;
require '../vendor/autoload.php';
use Alipay\EasySDK\Kernel\Config;
use Alipay\EasySDK\Kernel\Factory;




class NewsController  extends Controller
{
    public function __construct(Request $request){
        $token = getToken($request);
        $uid =Redis::get("code:".$token);
        $this->uid=$uid;
    }

    public function add_news(Request $request){
        $news = $request->only("title","description","topping","faId","view","source","route","keywords");
        //title不存在 格式为空白字符 长度少于2大与20
        if(!array_key_exists('title',$news)||!preg_match('/^[\S\s]{2,100}$/u',$news['title'])) return ThrowApiExc('32001');
        //description不存在 格式为空白字符 长度大于100
        if(!array_key_exists('description',$news)||!preg_match('/^[\S\s]{1,400}$/u',$news['description'])) return ThrowApiExc('32003');
        //faId不存在 格式为非字数字 长度不等于1
        if(!array_key_exists('faId',$news)||!preg_match('/^[\d]{1,11}$/u',$news['faId'])) return ThrowApiExc('32034');
        $news['createdTime']=date("Y-m-d H:i:s",time());
        $news['updateTime']=date("Y-m-d H:i:s",time());
        $data['uid']=$this->uid;


        $res = DB::table("news")->insertGetId($news);

        $news_data = $request->only("content");
        $news_data['nid']=$res;
        $res_data = DB::table("news_data")->insertGetId($news_data);

        if($res){
            return [
                'status_code'      => 200,
                'message'     =>  '提交成功',
                'data' => $res
            ];
        }else{
            return [    
                'status_code'      => 200,
                'message'     =>  '提交失败 联系后端开发',
                'data' => $res  
            ];
        }

    }

    public function update_news(Request $request,$nid){
        $news = $request->only("title","description","topping","view","faId","source","route");
        //title不存在 格式为空白字符 长度少于2大与20
        if(array_key_exists('title',$news)&&!preg_match('/^[\S\s]{2,100}$/u',$news['title'])) return ThrowApiExc('32001');
        //description不存在 格式为空白字符 长度大于100
        if(array_key_exists('description',$news)&&!preg_match('/^[\S]{0,400}$/u',$news['description'])) return ThrowApiExc('32003');

        $news['updateTime']=date("Y-m-d H:i:s",time());


        $res = DB::table("news")->where("id",$nid)->update($news);

        $news_data = $request->only("content");
        $news['nid']=$res;
        $res_data = DB::table("news_data")->where("nid",$nid)->update($news_data);

        if($res){
            return [
                'status_code'      => 200,
                'message'     =>  '提交成功',
                'data' => $res
            ];
        }else{
            return [
                'status_code'      => 200,
                'message'     =>  '提交失败 联系后端开发',
                'data' => $res
            ];
        }   
    }

        

    public function delete_news($nid){
        $res = DB::table("news")->where("id",$nid)->update(["status"=>9]);
        if($res){
            return [
                'status_code'      => 200,
                'message'     =>  '删除成功',
                'data' => $res
            ];
        }else{
            return [
                'status_code'      => 200,
                'message'     =>  '删除失败 联系后端开发',
                'data' => $res
            ];
        }
    }

    public function select_news(Request $request){
        $data = $request->only('status','faId');
        //32005不存在 格式为非字数字 长度不等于1 9删除
        if(!array_key_exists('status',$data)||!preg_match('/^[\d]{1}$/u',$data['status'])) return ThrowApiExc('32005');
        if(array_key_exists('faId',$data)&&!preg_match('/^[\d]{1,10}$/u',$data['faId'])) return ThrowApiExc('32034');
        $where=[];
        if(array_key_exists('faId',$data)){
            $whereIn=select_news_action($data['faId']);
        }
        $where[]=["n.status",$data['status']];
        if(array_key_exists('faId',$data)){

        }
        if(isset($whereIn)){
            $data = DB::table("news as n")
                    ->leftJoin("news_data as nd","nd.nid","=","n.id")
                    ->leftJoin("action as a","a.id","=","n.faId")
                    ->where($where)
                    ->whereIn("n.faId",$whereIn)
                    ->select("n.*","a.title as actionTitle","a.route")
                    ->orderBy("n.id","desc")
                    ->paginate(10)->toArray();
        }else{
            $data = DB::table("news as n")
                    ->leftJoin("news_data as nd","nd.nid","=","n.id")
                    ->leftJoin("action as a","a.id","=","n.faId")
                    ->where($where)
                    ->select("n.*","a.title as actionTitle","a.route")
                    ->orderBy("n.id","desc")
                    ->paginate(10)->toArray();
        }
        

        
        foreach($data['data'] as $k=>$v){
            // $data[$k]['createdTime']=date("Y-m-d",strtotime($v['createdTime']));
            $data['data'][$k]['createdTime']=date("Y-m-d",strtotime($v['createdTime']));
        }

        if($data){
            return [
                'status_code'      => 200,
                'message'     =>  '查询成功',
                'data' => $data
            ];
        }else{
            return [
                'status_code'      => 200,
                'message'     =>  '查询失败 联系后端开发',
                'data' => $data
            ];
        }
    }

    public function recovery_news($nid){
        $res = DB::table("news")->where("id",$nid)->update(["status"=>1]);
        return [
            'status_code'      => 200,
            'message'     =>  '删除失败 联系后端开发',
            'data' => $res
        ];
    }
    public function select_news_content($nid){

        $data = DB::table("news as n")
                ->leftJoin("news_data as nd","n.id","=","nd.nid")
                ->where("n.id",$nid)->first();
        DB::table("news")->where("id",$nid)->increment("view");
        $data['createdTime']=date("Y-m-d",strtotime($data['createdTime']));
        $aids = select_news_action(18);

        $data2 = DB::table("news as n")
                ->leftJoin("news_data as nd","n.id","=","nd.nid")
                ->select("n.title","n.id")
                ->inRandomOrder()
                ->limit(3)
                ->where("n.faId",$data['faId'])
                ->where("n.status","!=",9)
                ->where("n.id","!=",$nid)->get()->toArray();


        $data['relevant']=$data2;

        if($data){
            return [
                'status_code'      => 200,
                'message'     =>  '查询成功',
                'data' => $data
            ];
        }else{
            return [
                'status_code'      => 200,
                'message'     =>  '查询失败 联系后端开发',
                'data' => $data
            ];
        }
    }

    public function select_os_news(Request $request){

        $data = $request->only("title");
        $NewsOs=new NewsOSController($request);

        $res = $NewsOs->select_title($data['title']);

        return [
            'status_code'      => 200,
            'message'     =>  '查询成功',
            'data' =>  $res
        ];

    }


    // public function demo(){
    //     $alipay = new AlipayController();
    //     return $alipay->index();
    // }

    public function pay($quid){




        $options = new Config();

        $options->protocol = 'https';
        $options->gatewayHost = 'openapi.alipaydev.com';
        $options->signType = 'RSA2';

        $options->appId = '2016091400510682';
        // 为避免私钥随源码泄露，推荐从文件中读取私钥字符串而不是写入源码中
        $options->merchantPrivateKey = 'MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCrHYMTN4ZVryE6lSfKgADaAtfNS+4vYRXB1hwdwhegVCzsU8q3LkI5U45bVfO5PYaLl/Y/uYDyiX+E0Rq+5FOZunsvPV2TXolwFUVrIFUd2XPYLhrmEF5Sj2bqgrFXy1SHyEvMzSZ0LBiPSku86hVY5ApT+46iYfHcazf4hsnbQAe6d+OeXez35usdkmJ0Ifb/1iS0wmqzKLDZlw74+1ASE0pQTwphtLamNz4aEVQgX7a2+KZ3BqEic83LDztfEQEfnSjuobXYOQxF0GH67WozIhIBkn1us8g2hs2Nuf6rCzQEjK+MAgcOPDRR4YcJHI6cmSZb3adVAL9tmuPZnGqHAgMBAAECggEBAJ1CRCI3F0hL6Rfz2Fvsg9vYXQgZzk7QxLQd2D0pEZmRgq+22ki7RLV2qxAZ0CHf/3TvNaqfC3jbEMy5eAETyhkwHuHtXcCAU4MkqWWok1EZdbOpu6LQTD9H92dysRVkks0vMSqJJ9wAYpndx/lYkEHfYfaI7C8kIKlYCFppVb4ed1rorQwt4pNhfNKBZoqPTGkjl34hkNED9EbJapzR5JF70G6ilov+7fupHrpni+y0wsHdHFUTh11ZqUTCn1QZdSDVQMqNEXeIshxwKPJJnCUgEQGx2ooQO0X+bIz3ZvrOP2gMG9DYtsikWPjndYRykJwzbsq8BdLkwaAGv2cz5eECgYEA84lz6/0RI1iyjVhyQk8Rb9IZCvOipojbBA4/pREjxPXqqIhJeP34nXA9KJYcQeUASkKmRC7/vgA0GUd/VmWcKyHJKb4EU12EAOqeNw8rfaiSCkcczVkC7wrSwG5kI+YGqMg8HPpm/a7Xu0qBnkdkdOlRpw6AVnBvkOrmfpSbclkCgYEAs99FraLM9WmQh9CTNnWcHVwIorPd7rWCJQRohQ5W9rTj2CIZjoFe3vG4Pn23cqnPwTrMPcUU/PSPvK5sXpMWSQ5v3BDOOtrTD9+yKoCjIefkNDsUs6n1Izyc0yznG2iMxqVlABr3iOl9pSafHnTSL0fLsCwbK1dVTwf19tqCZ98CgYANpS3xkwRazqVydfow7O01LrhofK4oVpKu731xajxu1LiJKNm1BcXgTGGg3IhIyOPzRTi7qUZ7BtfkcrUXyimt4P68cAEeCqdSxdKHkzoEmGVWXhWnC822Rwz36zeBK2pEGrQDi6QpoppDzDDnBWkDg+8nRRC7xyD5JbA0d28eQQKBgGKcQB3uR8EvS445ucs8dQbfgth4FW6d0airnwV7FBASoWrHXw1yPWmqSSDxWRYipIRB0OD4YAZBqV9+nGjI6InKwWZ7TCSV/OoR8CI+/bBD6ib8UOAiiAL2Yt+fGWA8VBk/aXzCS/yiTUCySL+wud4z1SZTN93t9hXqvlzD9IQvAoGAS2P6dneR4inJZpgUhkEQk2R2GLfwvxEuRZ8KAZv9FowxX8XDGk94prQVJAiTBPUahp7GI6KSsLF4Tuc8kJtJKPT5kSj205MmiaDZQFxtw20Ae4Jn8XqCon2uNLAG4X7UMdOVycWCSp/iX4GrQbgtdw9tyNCkxAB4PNCl1awfHYE=';

        //注：如果采用非证书模式，则无需赋值上面的三个证书路径，改为赋值如下的支付宝公钥字符串即可
        $options->alipayPublicKey = 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAnGzkG9Cv2aSa1cITlUtnMStNYfCASfDljwclwtIadTCJyA0V5dPzLw+EeIro2PhFdJzPb078P2k3pI+1PVcIpgXFdaWWylo3yKrCL8t7VohA1Uk2W9ODtxjZZb841lTr4vUwaeuhZHQ7+EOQTvY2TeQx6QD03DxwHdEyPakegVs8Nfc9YCuSZJtagurejBotGL3lRG3iHivzcz9rhRzgtctDIGy7OCGY0GhyaG2KPrBPq1V6i9QiUAdElf8RzseVa3tzBgmgH+FHI6Bl5wfPW4fi5BqELIqtGoktEGl759/EQX9KkBeZPnbwx6CqkN/hemLqeioF9usopXbckR/8xQIDAQAB';
        DB::table("Q_q_p_users")->where("id",$quid)->update(['pay'=>1,'title'=>"离婚协议书","status"=>1]);
        //可设置异步通知接收服务地址（可选）
        $options->notifyUrl = "http://jiawen.jialilawyer.com/pug/api/Questionnaire/v1/news/pay_news/".$quid;
        // var_dump($options);
        // die;
        Factory::setOptions($options);
            $result = Factory::Payment()->Page()->pay("iPhone6 16G","202003262355".rand(100000,999999),"188.00","");
            return [
                'status_code'      => 200,
                'message'     =>  '查询成功',
                'data' => $result->body
            ];
        // return $res;
    }

    public function verification_pay($quid){
        $res = DB::table("Q_q_p_users")->where("id",$quid)->first();
        return [
            'status_code'      => 200,
            'message'     =>  '查询成功',
            'data' => $res['pay']
        ];
    }

    public function pay_news($quid){
        DB::table("Q_q_p_users")->where("id",$quid)->update(['pay'=>1,'title'=>"离婚协议书","status"=>1]);
    }


    public function news_hot(){
        $faids = select_news_action(18);
        $data_qian = DB::table("news as n")
                    ->leftJoin("news_data as nd","nd.nid","=","n.id")
                    ->leftJoin("action as a","a.id","=","n.faId")
                    ->where('n.status',1)
                    ->whereIn("n.faId",$faids)
                    ->select("n.*","a.title as actionTitle","a.route")
                    ->orderBy("view","desc")
                    ->limit(10)->get()->toArray();
        $data_hou = DB::table("news as n")
                    ->leftJoin("news_data as nd","nd.nid","=","n.id")
                    ->leftJoin("action as a","a.id","=","n.faId")
                    ->where('n.status',1)
                    ->whereIn("n.faId",$faids)
                    ->select("n.*","a.title as actionTitle","a.route")
                    ->offset(10)
                    ->orderBy("view","desc")
                    ->limit(5)->get();
        foreach($data_qian as $k=>$v){
            $data_qian[$k]['createdTime']=date("Y-m-d",strtotime($v['createdTime']));
        }
        $data['qian']=$data_qian;
        $data['hou']=$data_hou;
        if($data){
            return [
                'status_code'      => 200,
                'message'     =>  '提交成功',
                'data' => $data
            ];
        }else{
            return [
                'status_code'      => 200,
                'message'     =>  '提交失败 联系后端开发',
                'data' => $data
            ];
        }
    }


    //blade模版
    public function news_blade_list(Request $request,$page=1){
        //32005不存在 格式为非字数字 长度不等于1 9删除
        $where=[];
        $where[]=["n.status",1];
        $whereIn=select_news_action(18);
            $data = DB::table("news as n")
                    ->leftJoin("news_data as nd","nd.nid","=","n.id")
                    ->leftJoin("action as a","a.id","=","n.faId")
                    ->where($where)
                    ->whereIn("n.faId",$whereIn)
                    ->select("n.*","a.title as actionTitle","a.route")
                    ->paginate(10,['*'],'page',$page)->withUrl("/lhzs_",".html");

                    $action = new ActionController($request);
                    $action_data = $action->select_action(1);
        if($page==1){
            $ye="";
        }else{
            $ye="第".$page."页-";
        }
        $tdk = ['title'=>$ye."协议离婚_诉讼离婚_怎样写离婚协议书-蜗牛家事",'keywords'=>"怎样写离婚协议书,协议离婚,诉讼离婚,离婚子女抚养,离婚财产怎么分割,离婚过错方该分财产吗,北京离婚律师","description"=>"离婚知识栏目综合为您提供离婚知识性知识，包括怎样写离婚协议书，协议离婚，诉讼离婚，离婚子女抚养，离婚财产怎么分割等内容，在这里能充分了解离婚的各种信息，助您及时解决离婚问题，快速离婚。"];
        return view('pc.news_list', ['action_data' => $action_data[0]['data'],'data'=>$data,'tdk'=>$tdk,'route'=>'lhzs']);

    }

    public function news_blade_list_faId(Request $request,$route,$page=1){
        //32005不存在 格式为非字数字 长度不等于1 9删除
        $where=[];
        $where[]=["n.status",1];
        $where[]=["a.route",$route];
        $data = DB::table("news as n")
                ->leftJoin("news_data as nd","nd.nid","=","n.id")
                ->leftJoin("action as a","a.id","=","n.faId")
                ->where($where)
                ->select("n.*","a.title as actionTitle","a.route")
                ->paginate(10,['*'],'page',$page)->withUrl("/lhzs/".$route."_",".html");

        $action = new ActionController($request);
        $action_data = $action->select_action(1);

        // var_dump($route,$page);
        if($page==1){
            $ye="";
        }else{
            $ye="第".$page."页-";
        }
        $tdkData = DB::table("action")->where("route",$route)->first();
        if($tdkData){
            $tdk = ['title'=>$ye.$tdkData['tit'],'keywords'=>$tdkData['keywords'],"description"=>$tdkData['description']];
        }else{
            $tdk = ['title'=>"测试titile",'keywords'=>"测试keywords","description"=>"测试description"];
        }

        return view('pc.news_list', ['action_data' => $action_data[0]['data'],'data'=>$data,'tdk'=>$tdk,'route'=>$route]);

    }

    public function select_os_blade_news(Request $request){
        $data = $request->only("title");
        if(!array_key_exists('title',$data)){
            return view('pc.news_list_select', ['action_data' => [],'data'=>[],'getTitle'=>""]);
        };
        $NewsOs=new NewsOSController($request);

        $res = $NewsOs->select_title($data['title']);
        
        $action = new ActionController($request);
        $action_data = $action->select_action(1);
        // var_dump($res);
        // die;
        return view('pc.news_list_select', ['action_data' => $action_data[0]['data'],'data'=>$res,'getTitle'=>$data['title']]);
    }

    public function news_blade_show($route,$newsId){
        $data = DB::table("news as n")
                ->leftJoin("news_data as nd","n.id","=","nd.nid")
                ->leftJoin("action as a","a.id","=","n.faId")
                ->select("n.*","nd.*","a.title as actionTitle","a.route")
                ->where("n.id",$newsId)->first();
        DB::table("news")->where("id",$newsId)->increment("view");
        $data['createdTime']=date("Y-m-d",strtotime($data['createdTime']));
        $aids = select_news_action(18);

        $data2 = DB::table("news as n")
                ->leftJoin("news_data as nd","n.id","=","nd.nid")
                ->leftJoin("action as a","n.faid","=","a.id")
                ->select("n.title","n.id","a.route")
                ->inRandomOrder()
                ->limit(3)
                ->where("n.faId",$data['faId'])
                ->where("n.status","!=",9)
                ->where("n.id","!=",$newsId)->get()->toArray();

    $data['content']=preg_replace('/style=\".*?\"/','style="text-indent:2em;"',$data['content']);
        
        $data['relevant']=$data2;
        
        $hot = $this->news_hot();
        
        return view('pc.news_show', ['data'=>$data,'hot'=>$hot['data'],'route'=>$route]);
    }

    public function index(){
        $hot = $this->news_hot();
        unset($hot['data']['qian'][9]);
        
        // var_dump($hot['data']['qian']);
        // die;
        return view('pc.index',['hot'=>$hot['data']['qian']]);
    }

    public function m_select_os_blade_news(Request $request){
        $data = $request->only("title");
        if(!array_key_exists('title',$data)){
            return view('m.msearch', ['action_data' =>[],'data'=>[],'title'=>""]);
        };
        $NewsOs=new NewsOSController($request);

        $res = $NewsOs->select_title($data['title']);
        
        $action = new ActionController($request);
        $action_data = $action->select_action(1);
        // var_dump($res);
        // die;
        return view('m.msearch', ['action_data' => $action_data[0]['data'],'data'=>$res,"title"=>$data['title']]);
    }
    public function m_news_blade_list(Request $request,$page=1){
        //32005不存在 格式为非字数字 长度不等于1 9删除
        $where=[];
        $where[]=["n.status",1];
        $whereIn=select_news_action(18);
            $data = DB::table("news as n")
                    ->leftJoin("news_data as nd","nd.nid","=","n.id")
                    ->leftJoin("action as a","a.id","=","n.faId")
                    ->where($where)
                    ->whereIn("n.faId",$whereIn)
                    ->select("n.*","a.title as actionTitle","a.route")
                    ->paginate(10,['*'],'page',$page)->withUrl("/lhzs_",".html");

        $action = new ActionController($request);
        $action_data = $action->select_action(1);

        $tdk = ['title'=>"协议离婚_诉讼离婚_怎样写离婚协议书-蜗牛家事",'keywords'=>"怎样写离婚协议书,协议离婚,诉讼离婚,离婚子女抚养,离婚财产怎么分割,离婚过错方该分财产吗,北京离婚律师","description"=>"离婚知识栏目综合为您提供离婚知识性知识，包括怎样写离婚协议书，协议离婚，诉讼离婚，离婚子女抚养，离婚财产怎么分割等内容，在这里能充分了解离婚的各种信息，助您及时解决离婚问题，快速离婚。"];

        return view('m.news_list', ['action_data' => $action_data[0]['data'],'data'=>$data,'tdk'=>$tdk,'route'=>"/"]);
    }
    public function m_news_blade_list_faId(Request $request,$route,$page=1){
        //32005不存在 格式为非字数字 长度不等于1 9删除
        $where=[];
        $where[]=["n.status",1];
        $where[]=["a.route",$route];

            $data = DB::table("news as n")
                    ->leftJoin("news_data as nd","nd.nid","=","n.id")
                    ->leftJoin("action as a","a.id","=","n.faId")
                    ->where($where)
                    ->select("n.*","a.title as actionTitle","a.route")
                    ->paginate(10,['*'],'page',$page)->withUrl("/lhzs_",".html");
                    
        $action = new ActionController($request);
        $action_data = $action->select_action(1);
        
        $tdkData = DB::table("action")->where("route",$route)->first();
        if($tdkData){
            $tdk = ['title'=>$tdkData['tit'],'keywords'=>$tdkData['keywords'],"description"=>$tdkData['description']];
        }else{
            $tdk = ['title'=>"协议离婚_诉讼离婚_怎样写离婚协议书-蜗牛家事",'keywords'=>"怎样写离婚协议书,协议离婚,诉讼离婚,离婚子女抚养,离婚财产怎么分割,离婚过错方该分财产吗,北京离婚律师","description"=>"离婚知识栏目综合为您提供离婚知识性知识，包括怎样写离婚协议书，协议离婚，诉讼离婚，离婚子女抚养，离婚财产怎么分割等内容，在这里能充分了解离婚的各种信息，助您及时解决离婚问题，快速离婚。"];
        }
        return view('m.news_list', ['action_data' => $action_data[0]['data'],'data'=>$data,'tdk'=>$tdk,'route'=>$route]);
    }
    public function m_news_blade_show($route,$newsId){
        $data = DB::table("news as n")
                ->leftJoin("news_data as nd","n.id","=","nd.nid")
                ->where("n.id",$newsId)->first();
                $data['route']=$route;
        DB::table("news")->where("id",$newsId)->increment("view");
        $data['createdTime']=date("Y-m-d",strtotime($data['createdTime']));
        $aids = select_news_action(18);

        $data2 = DB::table("news as n")
                ->leftJoin("news_data as nd","n.id","=","nd.nid")
                ->leftJoin("action as a","n.faId","=","a.id")
                ->select("n.title","n.id","a.route")
                ->inRandomOrder()
                ->limit(3)
                ->where("n.faId",$data['faId'])
                ->where("n.status","!=",9)
                ->where("n.id","!=",$newsId)->get()->toArray();

        $data['relevant']=$data2;

        $hot = $this->news_hot();
        $data['content']=preg_replace('/style=\".*?\"/','style="text-indent:2em;"',$data['content']);

        return view('m.news_show', ['data'=>$data,'hot'=>$hot['data'],'route'=>$route]);
    }
    public function m_news_blade_list_remen(Request $request){
        //32005不存在 格式为非字数字 长度不等于1 9删除
        $where=[];
        $where[]=["n.status",1];
        $whereIn=select_news_action(18);
        $data = $this->news_hot()['data']['qian'];
        
        // var_dump($data);
        // die;
        $action = new ActionController($request);
        $action_data = $action->select_action(1);
        $tdk = ['title'=>"协议离婚_诉讼离婚_怎样写离婚协议书-蜗牛家事",'keywords'=>"怎样写离婚协议书,协议离婚,诉讼离婚,离婚子女抚养,离婚财产怎么分割,离婚过错方该分财产吗,北京离婚律师","description"=>"离婚知识栏目综合为您提供离婚知识性知识，包括怎样写离婚协议书，协议离婚，诉讼离婚，离婚子女抚养，离婚财产怎么分割等内容，在这里能充分了解离婚的各种信息，助您及时解决离婚问题，快速离婚。"];

        return view('m.hot', ['action_data' => $action_data[0]['data'],'data'=>$data,'tdk'=>$tdk,'route'=>""]);
    }

    public function czzn(){
        $tdk = ['title'=>"离婚协议书操作指南_离婚协议书生成-蜗牛家事",'keywords'=>"离婚协议书下载,离婚协议书操作指南,离婚协议书生成,手写离婚协议书","description"=>"离婚协议书操作指南提供离婚协议书生成产品在使用中的操作介绍，建议可在使用前或使用中根据指南，了解产品的具体使用方法，准确高效率的生成离婚协议书。"];
        return view('pc.czzn');
    }

    public function xysdzbz(Request $request,$page=1){
        $where=[];
        $where[]=["n.status",1];
        $where[]=["a.id",21];
        $data = DB::table("news as n")
                ->leftJoin("news_data as nd","nd.nid","=","n.id")
                ->leftJoin("action as a","a.id","=","n.faId")
                ->where($where)
                ->select("n.*","a.title as actionTitle","a.route")
                ->paginate(10,['*'],'page',$page)->withUrl("/dzlhxys2/xysdzbz_",".html");

        $tdk = ['title'=>"怎么写离婚协议书_离婚协议书注意事项-蜗牛家事",'keywords'=>"怎么写离婚协议书,离婚协议书注意事项,写离婚协议书,离婚协议书起草","description"=>"不知道怎么写离婚协议书，离婚协议书生成产品使用时有问题不清楚，常见问题会为您讲解离婚协议书产品生成中的注意事项及问题，为您提供便利，如您在离婚协议书起草时还有部分问题可随时反馈。"];
        return view('pc.xysbz',['data'=>$data]);
    }


    public function xysdzbz_show(Request $request,$newsId){
        $data = DB::table("news as n")
                ->leftJoin("news_data as nd","n.id","=","nd.nid")
                ->leftJoin("action as a","a.id","=","n.faId")
                ->select("n.*","nd.*","a.title as actionTitle","a.route")
                ->where("n.id",$newsId)->first();
        DB::table("news")->where("id",$newsId)->increment("view");
        $data['createdTime']=date("Y-m-d",strtotime($data['createdTime']));
        $aids = select_news_action(18);

        $data2 = DB::table("news as n")
                ->leftJoin("news_data as nd","n.id","=","nd.nid")
                ->leftJoin("action as a","n.faid","=","a.id")
                ->select("n.title","n.id","a.route")
                ->inRandomOrder()
                ->limit(3)
                ->where("n.faId",$data['faId'])
                ->where("n.status","!=",9)
                ->where("n.id","!=",$newsId)->get()->toArray();

        $data['content']=preg_replace('/style=\".*?\"/','style="text-indent:2em;"',$data['content']);
        
        $data['relevant']=$data2;
        
        $hot = $this->news_hot();
        
        return view('pc.xysbz_show', ['data'=>$data,'hot'=>$hot['data']]);
    }


    public function userAgreement(){
        return view('pc.userAgreement');
    }


}